#include <iostream>
#include <vector>
using namespace std;

vector<int> ufs;

int find(int x)
{
    if(ufs[x] < 0) return x;
    else return ufs[x] = find(ufs[x]);
}

void M(int a, int b)
{
    int pa = find(a), pb = find(b);
    if(pa == pb && pa >= 0) return;
    ufs[pa] += ufs[pb];
    ufs[pb] = pa;
}

int main()
{
    char c;
    int n, m, a, b; cin >> n >> m;
    ufs.resize(n, -1);
    
    while(m--)
    {
        cin >> c >> a >> b;
        a--, b--;
        if(c == 'M') M(a, b);
        else if(find(a) == find(b)) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}